﻿using System;
using System.Collections.Generic;

namespace Crm
{
    public sealed class Session
    {
        private static volatile Session instance;
        private static object syncRoot = new Object();
        private Session() { }
        public static Session Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                            instance = new Session();
                    }
                }

                return instance;
            }
        }

        private Dictionary<string, object> _collection = new Dictionary<string, object>();
        public void Add(string key, object value)
        {
            if (_collection.ContainsKey(key))
                _collection[key] = value;
            else
                _collection.Add(key, value);
        }
        public T GetValue<T>(string key)
        {
            System.Globalization.CultureInfo provider = new System.Globalization.CultureInfo("tr-TR");
            if (_collection.ContainsKey(key))
                return (T)Convert.ChangeType(_collection[key], typeof(T), provider);
            else
                return (T)Convert.ChangeType(null, typeof(T), provider);
        }
        public void Delete(string key)
        {
            if (_collection.ContainsKey(key))
                _collection.Remove(key);
        }
    }
}
